package AsLayers.Layer
{
	import AsLayers.BaseType.Bounds;
	import AsLayers.BaseType.Pixel;
	import AsLayers.Map;
	import flash.display.DisplayObject;
	import mx.containers.Canvas;

	public class Marker implements ILayer
	{
		private var map:Map
		private var container:Canvas=new Canvas()
		private var markers:Array=new Array()
		public function Marker()
		{
		}
	    public function getMap():Map{
			return this.map
		}
		public function setMap(map:Map):void
		{
            this.map=map;
            this.container.clipContent=false
            map.getLayerContainer().addChildAt(this.container,map.getLayerContainer().getChildren().length)
           /// map.getLayerContainer().addChildAt(
		}
		
		public function getUrl(bounds:Bounds):String
		{
             return null
		}
		
		public function moveTo(bounds:Bounds, zoomChanged:Boolean):void{
			if(zoomChanged){
				for(var i:int=0;i<this.markers.length;i++){
					trace("redraw...")
					this.drawMarker(this.markers[i])
		        }
			}
		}
		public function addMarker(marker:AsLayers.Marker):void{
			this.markers.push(marker);
			this.drawMarker(marker);
		}
		public function drawMarker(marker:AsLayers.Marker):void{
			var px:Pixel=this.map.getLayerPxFromLonLat(marker.getLonLat())
			var draw:DisplayObject=marker.draw(px);
			if(draw!=null)
			   this.container.addChild(draw)
		}
		public function removeMarker(marker:AsLayers.Marker):void{
			for(var i:int=0;i<this.markers.length;i++){
				if(this.markers[i]==marker){
					this.markers[i].destroy();
					this.markers.splice(i,1);
				}
			}
		}
		public function clearMarkers():void{
			for(var i:int=0;i<this.markers.length;i++){

					this.markers[i].destroy();
			}
			this.markers=[];
		}
	}
}